package com.example.mybatisplus.demo.controller;

/**
 *  @ author  zengqingfa
 *  @ created in    2020/2/21  21:05
 *
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.demo.entity.UserInfoEntity2AR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "UserInfoARController用户信息", tags = "UserInfoARController用户信息")
@RestController
@RequestMapping("/userInfoAr")
public class UserInfoARController {

    /**
     * 根据ID获取用户信息13333333
     * @author zengqingfa
     * @param userId
     * @return
     */
    @GetMapping("/getInfo")
    public UserInfoEntity2AR getInfo(@RequestParam Long userId) {
        UserInfoEntity2AR userInfoEntity2AR = new UserInfoEntity2AR();
        userInfoEntity2AR.setId(userId);
        UserInfoEntity2AR userInfoEntity = userInfoEntity2AR.selectById();
        return userInfoEntity;
    }


    /**
     * 查询全部信息
     *
     * @return
     */
    @ApiOperation("查询全部信息")
    @GetMapping("/getList")
    public List<UserInfoEntity2AR> getList() {
        UserInfoEntity2AR userInfoEntity2AR = new UserInfoEntity2AR();
        List<UserInfoEntity2AR> list = userInfoEntity2AR.selectAll();
        return list;
    }


    /**
     * 分页查询全部数据
     *
     * @return
     */
    @ApiOperation("分页查询全部数据")
    @GetMapping("/getInfoListPage")
    public IPage<UserInfoEntity2AR> getInfoListPage() {
        UserInfoEntity2AR userInfoEntity2AR = new UserInfoEntity2AR();
        QueryWrapper wrapper = new QueryWrapper();
        //需要在Config配置类中配置分页插件
        IPage<UserInfoEntity2AR> page = new Page<>();
        page.setCurrent(5); //当前页
        page.setSize(1);    //每页条数
        page = userInfoEntity2AR.selectPage(page, wrapper);
        return page;
    }


    /**
     * 新增用户信息
     */
    @ApiOperation("新增用户信息")
    @PostMapping("/saveInfo")
    public void saveInfo() {
        UserInfoEntity2AR userInfoEntity = new UserInfoEntity2AR();
        userInfoEntity.setName("小龙");
        userInfoEntity.setSkill("JAVA");
        userInfoEntity.setAge(18);
        userInfoEntity.setFraction(59L);
        userInfoEntity.setEvaluate("该学生是一个在改BUG的码农");
        userInfoEntity.insert();
    }
}

